package com.iknow.activity;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask.Status;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.iknow.IKnow;
import com.iknow.data.QingBo;
import com.iknow.task.CommonTask.QingboTask;
import com.iknow.task.TaskParams;
import com.iknow.ui.model.QingBoAdapter;
import com.iknow.view.widget.PullToRefreshListView;
import java.util.List;

public class SearchableActivity extends QingboWithNoHeaderActivity
{
  protected List<QingBo> cacheList;
  private Context mContext = null;
  private View.OnClickListener mOnClickListener;
  public ProgressDialog pd;
  protected String query;
  protected Button search;
  public EditText searchResult;

  public SearchableActivity()
  {
    this.cacheList = null;
    this.search = null;
    this.searchResult = null;
    this.query = null;
    this.pd = null;
    this.mOnClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        this.this$0.query = this.this$0.searchResult.getText().toString();
        this.this$0.mAdapter.clearQingBoList();
        this.this$0.mAdapter.notifyDataSetChanged();
        this.this$0.mListView.prepareForRefresh();
        this.this$0.mListViewFooter.setVisibility(8);
        ((InputMethodManager)this.this$0.getSystemService("input_method")).hideSoftInputFromWindow(this.this$0.searchResult.getWindowToken(), 0);
        this.this$0.refreshData();
      }
    };
  }

  List<QingBo> doGetLocolData()
  {
    return null;
  }

  public void doMySearch(String paramString)
  {
    if (!(IKnow.IsNetAviable()))
      Toast.makeText(this.mContext, this.mContext.getString(2131361878), 0).show();
    while (true)
    {
      return;
      this.mListView.prepareForRefresh();
      refreshData();
    }
  }

  void doNeedMore()
  {
    if ((this.mTask != null) && (this.mTask.getStatus() == AsyncTask.Status.RUNNING));
    while (true)
    {
      return;
      this.mGetMoreButton.setText("正在载入数据...");
      this.mTask = new CommonTask.QingboTask();
      this.mTask.setListener(this.mGetMoreListener);
      this.mTask.setAdapter(this.mAdapter);
      TaskParams localTaskParams = new TaskParams();
      localTaskParams.put("keyword", this.query);
      localTaskParams.put("offset", Integer.valueOf(getCurrentListLength()));
      localTaskParams.put("length", Integer.valueOf(20));
      CommonTask.QingboTask localQingboTask = this.mTask;
      TaskParams[] arrayOfTaskParams = new TaskParams[1];
      arrayOfTaskParams[0] = localTaskParams;
      localQingboTask.execute(arrayOfTaskParams);
    }
  }

  protected ProgressDialog getProgressDialog()
  {
    if (this.pd == null)
      this.pd = ProgressDialog.show(this.mContext, "提示", "正在搜索,请稍等...");
    return this.pd;
  }

  void getServerData()
  {
  }

  public void onCreate(Bundle paramBundle)
  {
    this.TAG = "SearchableActivity";
    addView(2130903069);
    super.onCreate(paramBundle);
    this.mContext = this;
    this.searchResult = ((EditText)findViewById(2131296377));
    this.search = ((Button)findViewById(2131296378));
    this.search.setOnClickListener(this.mOnClickListener);
    if ("android.intent.action.SEARCH".equals(getIntent().getAction()))
    {
      this.query = getIntent().getStringExtra("query");
      doMySearch(this.query);
    }
  }

  public void onNewIntent(Intent paramIntent)
  {
    String str;
    super.onNewIntent(paramIntent);
    if ("android.intent.action.SEARCH".equals(paramIntent.getAction()))
    {
      str = paramIntent.getStringExtra("query");
      if ((str != this.query) && (!(str.equals(this.query))))
        break label44;
    }
    while (true)
    {
      return;
      label44: this.query = str;
      this.cacheList = null;
      this.mAdapter.clearQingBoList();
      this.mAdapter.notifyDataSetChanged();
      this.mListView.prepareForRefresh();
      this.mListViewFooter.setVisibility(8);
      doMySearch(this.query);
      this.searchResult.setText(this.query);
    }
  }

  protected void onResume()
  {
    super.onResume();
  }

  public void onSubmitefailure(String paramString)
  {
    Toast.makeText(this, paramString, 0).show();
  }

  void refreshData()
  {
    if ((this.mTask != null) && (this.mTask.getStatus() == AsyncTask.Status.RUNNING));
    while (true)
    {
      return;
      this.mTask = new CommonTask.QingboTask();
      this.mTask.setListener(this.mTaskListener);
      this.mTask.setAdapter(this.mAdapter);
      TaskParams localTaskParams = new TaskParams();
      localTaskParams.put("keyword", this.query);
      localTaskParams.put("offset", Integer.valueOf(0));
      localTaskParams.put("length", Integer.valueOf(20));
      CommonTask.QingboTask localQingboTask = this.mTask;
      TaskParams[] arrayOfTaskParams = new TaskParams[1];
      arrayOfTaskParams[0] = localTaskParams;
      localQingboTask.execute(arrayOfTaskParams);
    }
  }
}